package com.bigintegerdemo;

import java.math.BigInteger;

/**
 * @Auther: shiquan
 * @Date: 2024/10/24 - 10 - 24 -17:55
 */
public class BigIntegerDemo2 {

    public static void main(String[] args) {
        /*
        public BigInteger add
        public BigInteger subtract
        public BigInteger multiply
        public BigInteger divide 除法获取商
        public BigInteger pow 次幂
        public boolean equals(Object x)
        public  BigInteger max
        public  BigInteger min
        public int intValue()  转为int类型整数 超出范围有误
         */

        //1 创建两个BigInteger对象    较小的化用valueof
        BigInteger bd1 = BigInteger.valueOf(10);
        BigInteger bd2 = BigInteger.valueOf(1);
        
        //2加法
        BigInteger bd3 = bd1.add(bd2);
        System.out.println(bd3);
        
        //3 除法 获取商和余数
        BigInteger[] arr = bd1.divideAndRemainder(bd2);
        System.out.println(arr[0]); //2   尚为2  余数为0
        System.out.println(arr[1]);//0
        
        //4 比较是否一样
        boolean result = bd1.equals(bd2);
        System.out.println(result);
        
        //5 次幂
        BigInteger bd4 = bd1.pow(2);
        System.out.println(bd4);;

        //6 max
        BigInteger bd5 = bd1.max(bd2);
        System.out.println(bd5.equals(bd1));
        System.out.println(bd5.equals(bd2));

        //转为int类型整数  超出范围数据有误
        BigInteger bd6 = BigInteger.valueOf(10000L);
        int i = bd6.intValue();
        System.out.println(i);

    }
}
